//#include - tells the compiler to add code here //.h - header ... at the top #include #include using namespace std; //size of the array stays empty when it is passed to a function //a copy of the array is NOT made void displayBoard(char board[]) { //display tic-tac-toe board cout << board[0] << '|' << board[1] << '|' << board[2] << endl; cout << "-----" << endl; cout << board[3] << '|' << board[4] << '|' << board[5] << endl; cout << "-----" << endl; cout << board[6] << '|' << board[7] << '|' << board[8] << endl; } void main() { char board[9] = { '1', '2', '3', '4', '5', '6', '7', '8', '9'}; char currentPlayer = 'X'; do { //the address of the list is passed to the function displayBoard(board); int move; do { cin >> move; } while (move < 1 || move > 9); //move is in the range 1-9, but the indexes are 0-8 board[move - 1] = currentPlayer; //change whose turn it is if (currentPlayer == 'X') { currentPlayer = 'O'; } else { currentPlayer = 'X'; } } while (true); } //void main() //{ // const int SIZE = 100; // //size = 100, size must be a literal or constant whole number // //no varible size, no fractions // int A[SIZE]; // //range of indexes aka subscripts - 0 thru (SIZE-1) // //out of bounds error-when you use an index that is too big or small // for (int i = 0; i < SIZE; i++) // { // A[i] = 0; // } // for (int i = 0; i < SIZE; i++) // { // cout << A[i] << endl; // display A sub i // } // //cout << A << endl; //do not do this // // // //int B[10] = {2,4,6,8,10,12,14,16,18,20}; // //int B[10] = {0}; // int B[10] = { 1 }; // for (int i = 0; i < 10; i++) // { // cout << B[i] << endl; // display A sub i // } // int rolls[13] = {0}; //} //void main() //{ // //time(NULL) - returns the number of seconds since Jan 1 1970 // srand(time(NULL)); // seeds the random number generator // // for (int i = 0; i < 10; i++) // { // cout << (rand() % 100) + (rand() % 100) << endl; // } //}